package com.yueyang.sojourn.server.service.sojourn.tourist;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.yueyang.sojourn.server.model.enums.StatusEnum;
import com.yueyang.sojourn.server.model.po.SojournTourist;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * 游客服务
 * @author andy.yang
 * @version v1
 * @summary
 * @Copyright (c) 2019, yueyang Group All Rights Reserved.
 * @since 2020/3/17
 */
@Service
public class SojournTouristService {
    @Resource
    SojournTouristMapper sojournTouristMapper;

    /**
     * 创建游客
     * @param tourist
     * @return
     */
    public Long add(SojournTourist tourist){
        tourist.setStatus(StatusEnum.VALID.getCode());
        sojournTouristMapper.insert(tourist);
        return tourist.getId();
    }

    /**
     * 编辑游客
     * @param tourist
     * @return
     */
    public int update(SojournTourist tourist){
        return sojournTouristMapper.update(tourist);
    }

    /**
     * 删除
     * @param touristId
     * @param userId
     * @return
     */
    public int delete(Long touristId,Long userId){
        return sojournTouristMapper.delete(touristId,userId);
    }
    /**
     * @param userId      所属用户id
     * @param pageNo      页码
     * @param pageSize    页大小
     * @return com.github.pagehelper.PageInfo<com.yueyang.sojourn.server.model.vo.SojournMerchVo>
     * @author Andy.yang
     * @summary 订单分页查询
     * @version v1
     * @since 2020-02-19
     */
    public PageInfo<SojournTourist> findPage(Long userId, Integer status,int pageNo, int pageSize) {
        PageInfo<SojournTourist> pageInfo = PageHelper.startPage(pageNo, pageSize)
                .doSelectPageInfo(() -> sojournTouristMapper.findBy(userId,status));
        return pageInfo;
    }

    /**
     * @param touristId      游客id
     * @return com.github.pagehelper.PageInfo<com.yueyang.sojourn.server.model.vo.SojournMerchVo>
     * @author Andy.yang
     * @summary 订单分页查询
     * @version v1
     * @since 2020-02-19
     */
    public SojournTourist findById(Long touristId) {
        return sojournTouristMapper.selectByPrimaryKey(touristId);
    }

    /**
     *
     * @param ids 遊客ids
     * @return
     */
    public List<SojournTourist> findByIds(List<Long> ids){
        return sojournTouristMapper.selectByIds(ids);
    }
}
